<? 
require 'config.php';
$domain = 'http://vnupdate.net';
$sitemap = '';
$sitemap .= '<url>
                <loc>'.$domain.'</loc>
                <changefreq>Hourly</changefreq>
                <priority>1.00</priority>
              </url>';
//các category
$db_menu = new db_query('SELECT * FROM categories_multi 
                         WHERE cat_active = 1');
$list_cat = $db_menu->resultArray();unset($db_menu);
foreach($list_cat as $cat){
    $sitemap .= '<url>';
    $sitemap .= '<loc>'.$domain.'/'.removeTitle($cat['cat_name']).'.htm</loc>';
    $sitemap .= '<changefreq>Hourly</changefreq>';
    $sitemap .= '<priority>0.80</priority>';
    $sitemap .= '</url>';
}
foreach($list_cat as $cat){
    //list bài mới
    $db_query = new db_query('SELECT new_id,new_title,new_date,
                                        new_cat_id,cat_id,cat_name
                                    FROM news 
                                    LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                    WHERE new_active = 1 AND new_cat_id = '.$cat['cat_id'].'
                                    ORDER BY new_id DESC 
                                    LIMIT 100');
    $list_news = $db_query->resultArray();unset($db_query);
    foreach($list_news as $news){
        $sitemap .= '<url>';
        $sitemap .= '<loc>'.$domain.generate_detail_url($news,$news['cat_name']).'</loc>';
        $sitemap .= '<lastmod>'.date("c",$news["new_date"]).'</lastmod>';
        $sitemap .= '<changefreq>Weekly</changefreq>';
        $sitemap .= '<priority>0.64</priority>';
        $sitemap .= '</url>';
    }
}
//sitemap  
$sitemap .= '<url>';
$sitemap .= '<loc>'.$domain.'/sitemap.xml'.'</loc>';
$sitemap .= '<changefreq>Daily</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
//tags  
$sitemap .= '<url>';
$sitemap .= '<loc>'.$domain.'/tags/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';

ob_clean();
?>
<?header ("Content-Type:text/xml");?>
<?php 
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<?=$sitemap?>
</urlset>
